package top.infopub.job.util;


import org.springframework.util.DigestUtils;

import java.util.Calendar;

public class PwdMD5Utils {

    public static String interfacePwdMD5(){
        //接口密码，密码生成策略：4位年+smz+两位月+smz+2位日期+用户名”lwsmz“的Md5，然后再MD5
        String smz="smz";
        String lwsmz="lwsmz";
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);//获取年份
        int month=cal.get(Calendar.MONTH)+1;//获取月份
        int day=cal.get(Calendar.DATE);//获取日
        String month_str=month+"";
        String day_str=day+"";
        if(month<10){
            month_str="0"+month;
        }
        if(day<10){
            day_str="0"+day;
        }
        String lwsmzMd5= DigestUtils.md5DigestAsHex(lwsmz.getBytes());
        String str=year+smz+month_str+smz+day_str+lwsmzMd5;
        return DigestUtils.md5DigestAsHex(str.getBytes());
    }


    public static String ssoPwdMD5(String code){
        String smz="GSGL";
        //String lwsmz="lwsmz";
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);//获取年份
        int month=cal.get(Calendar.MONTH)+1;//获取月份
        int day=cal.get(Calendar.DATE);//获取日
        String month_str=month+"";
        String day_str=day+"";
        if(month<10){
            month_str="0"+month;
        }
        if(day<10){
            day_str="0"+day;
        }
        String lwsmzMd5= DigestUtils.md5DigestAsHex(code.getBytes());
        String str=year+smz+month_str+smz+day_str+lwsmzMd5;
        return DigestUtils.md5DigestAsHex(str.getBytes());
    }
}
